package com.wujunhao1024.sqldp;

import com.wujunhao1024.sqldp.entity.Field;
import com.wujunhao1024.sqldp.strategy.Strategy;
import com.wujunhao1024.sqldp.workbench.Workbench;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.Select;

import java.util.List;

public class SqlDpParser {

    public static List<Field> parse(String sql) {
        Workbench workbench = new Workbench();
        Strategy strategy = new Strategy();
        try {
            // 使用 CCJSqlParserUtil 解析 SQL 字符串
            Statement statement = CCJSqlParserUtil.parse(sql);
            // 如果是 SELECT 语句，则可以转换为 Select 对象进行更详细的处理
            if (statement instanceof Select) {
                Select select = (Select) statement;
                strategy.selectFill(select, workbench);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return workbench.getResult();
    }
}
